package com.example.shop_2304.adapter

import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Order
import com.example.base.entity.OrderInfo
import com.example.shop_2304.R
import com.example.shop_2304.utils.GlideUtils

class OrderAdapter:BaseQuickAdapter<Order,BaseViewHolder>(R.layout.item_order) {
    override fun convert(holder: BaseViewHolder, item: Order) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)

        holder.setText(R.id.order_total,"共${item.totalNum}种商品，合计￥${item.payPrice}")
        if(item.orderStatus=="待付款"){
            holder.getView<TextView>(R.id.order_tv).text = "立即支付"
            holder.getView<TextView>(R.id.order_tv2).isVisible = false
        }else if(item.orderStatus=="待发货"){
            holder.getView<TextView>(R.id.order_tv).text = "催商家发货"
            holder.getView<TextView>(R.id.order_tv2).text = "申请退款"
        }else if(item.orderStatus=="待收货"){
            holder.getView<TextView>(R.id.order_tv).text = "确认收货"
            holder.getView<TextView>(R.id.order_tv2).text = "申请退款"
        }else if(item.orderStatus=="待评价"){
            holder.getView<TextView>(R.id.order_tv).text = "立即评价"
            holder.getView<TextView>(R.id.order_tv2).isVisible = false
        }
        //rv
        val rv = holder.getView<RecyclerView>(R.id.order_rv)
        //找到适配器  布局  布局复用加载预下单的item
        val orderDetailAdapter = OrderDetailAdapter()
        orderDetailAdapter.data.addAll(item.orderInfoList)
        rv.adapter = orderDetailAdapter
        rv.layoutManager = LinearLayoutManager(context)
    }
}

class OrderDetailAdapter :BaseQuickAdapter<OrderInfo,BaseViewHolder>(R.layout.item_preorder){
    override fun convert(holder: BaseViewHolder, item: OrderInfo) {
        GlideUtils.loadImage(context,item.image,holder.getView(R.id.car_image))
        holder.setText(R.id.car_storename,item.storeName)
        holder.setText(R.id.car_sku,"")
        holder.setText(R.id.car_price,"￥${item.price}")
        holder.setText(R.id.car_num,"X ${item.cartNum}")
    }

}